package util;

import java.util.ArrayList;
import java.util.Collections;

class ExtendSorterHandle<T extends Comparable<T>> implements Comparable<ExtendSorterHandle<T>> {
	public T m_value;
	public int m_index;

	public int compareTo(ExtendSorterHandle<T> another) {
		return m_value.compareTo(another.m_value);
	}
}

public class ExtendSorter {
	public static <T extends Comparable<T>> ArrayList<Integer> getIndiceAfterSorting(
					ArrayList<T> data) {

		ArrayList<ExtendSorterHandle<T>> extendData = new ArrayList<ExtendSorterHandle<T>>(
						data.size());
		for (int i = 0; i < data.size(); ++i) {
			ExtendSorterHandle<T> eSorter = new ExtendSorterHandle<T>();
			eSorter.m_value = data.get(i);
			eSorter.m_index = i;
			extendData.add(eSorter);
		}

		Collections.sort(extendData);

		ArrayList<Integer> indices = new ArrayList<Integer>(data.size());
		for (ExtendSorterHandle<T> element : extendData) {
			indices.add(element.m_index);
		}

		return indices;
	}
}
